#region Using directives

using System;
using System.Collections.Generic;
using System.Text;

using Weazel.Math;

#endregion

namespace Weazel.Gezel.Simulator.Reference
{
  class ConstantSignal : AbstractSignal
  {
    /// <summary>
    /// Caches the constant value
    /// </summary>
    private readonly Integer value;

    /// <summary>
    /// Constructs the ConstantSignal from the
    /// specified string value
    /// </summary>
    /// <param name="id">signal id</param>
    /// <param name="str">constant value as a string</param>
    public ConstantSignal(Symid id, string str): base(id, null)
    {
      value = new Integer(str);
    }

    /// <summary>
    /// Constructs the ConstantSignal from an existing integer.    
    /// </summary>
    /// <param name="id">signal id</param>
    /// <param name="i">Value of the signal as an Math.Integer</param>
    public ConstantSignal(Symid id, Integer i) : base(id, null)
    {
      value = i;
    }

    /// <summary>
    /// Returns the bitwidth that is
    /// needed to properly represent
    /// the constant value
    /// </summary>
    /// <returns></returns>
    internal override uint Width()
    {
      return (uint) value.Width;
    }

    /// <summary>
    /// Constants are not always unsigned in comparison to Gezel constants
    /// </summary>
    /// <returns></returns>
    internal override uint Signed()
    {
      return value.Signed ? 1u : 0u;
    }

    /// <summary>
    /// Just return the contained Integer value
    /// </summary>
    /// <param name="targetGeneration"></param>
    /// <returns>the constant value</returns>
    internal override Integer Evaluate(AbstractIpBlock ip, long targetGeneration)
    {
      return value;
    }

    public override bool TraceToSignal(Symid toSignalId, List<AbstractSignal> signals)
    {
      return false;
    }

    internal override Integer PeekValue()
    {
      return value;
    }
  }
}
